home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 584 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: lars.farm@nts.mh.se (Lars Farm)
  3. Newsgroups: comp.std.c++
  4. Subject: 'const' in header files
  5. Date: 28 Feb 1996 10:47:48 PST
  6. Organization: pv
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <AD5A0C5196681CA0D@sleipner.nts.mh.se>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Wed, 28 Feb 1996 13:42:41 +0100
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMTSjpEy4NqrwXLNJAQGMFAH/Ve58Jzwabed7dBsK8flE8REEGH0Gvxns
  13.     qb5LfCn+aVSpd/BSy5Y2WIQNA2BllntMCovQCuMEtYN1EDI5B7G7tQ==
  14.     =NZpy
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. This is a reply to a thread in c.l.c++.moderated. The moderator asked me to
  18. post this in com.std.c++ instead. The thread started with someone
  19. complaining about a warning for an unused variable where he had const float
  20. x = y; in a header.
  21.  
  22. Experts explained that this is as it should be for const float, but not for
  23. const int (I know that the std does not talk about warnings). The point is:
  24. The experts seems to find some kind of conceptual difference between named
  25. constant floats and named constant ints, such that declaring const int K =
  26. L; in a header is considered good practice but const float X = Y; in a
  27. header is not and justifies a warning. I don't think there should be any
  28. such difference.
  29.  
  30. In article <4ghtue$e1m@netlab.cs.rpi.edu>,
  31. orfanos@enst.enst.fr (Dimitri Papadopoulos) wrote:
  32.  
  33. >Also, do you mean that in C++ you can't replace #define by const
  34. >float? I'll have to switch back to #define!
  35.  
  36. I hope not. I don't get it. Every book (including Stroustrups) urges us to
  37. use const for named constants instead of #define. Linkage for consts is
  38. internal for this reason. Why should a user have to worry about the fact
  39. that a compiler writer implements float and int differently for named
  40. constants? const float can't be considered different from const int, const
  41. short, const long or const any built in type. 
  42.  
  43. This appears to be a hole in the standard. Maybe it should be tightened a
  44. little bit and require that named constants of built in types shall not be
  45. "instantiated" (directly as inline constants in generated code or as
  46. constant static data) unless actually used. The same kind of requirement is
  47. already in for templates. 
  48.  
  49.  
  50. --
  51. Lars Farm, lars.farm@nts.mh.se
  52. ---
  53. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  54.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  55.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  56.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  57.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  58. ]
  59.